<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./../../_template.xhtml"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://xmlns.jcp.org/jsf/core">

    <ui:define name="centro">
        <h:form>
            <h:panelGrid columns="1">
                <h:outputText value="Estado: #{contaBean.conta.situacao}" style="margin-left: 800px; margin-bottom: 20px; margin-top: 20px"
                              rendered="#{not empty contaBean.conta.id}"/>
            </h:panelGrid>
            <p:outputLabel value="Cadastro de Conta Bancária - Incluir" rendered="#{empty contaBean.conta.id}" style="font-size: x-large; margin-left: 25px" styleClass="labelInserir" />
            <p:outputLabel value="Cadastro de Conta Bancária - Alterar" rendered="#{not empty contaBean.conta.id}" style="font-size: x-large; margin-left: 25px" styleClass="labelAlterar" />

            <p:fieldset styleClass="fieldsetInsert" style=" margin-left: 25px">
                <p:messages />

                <h:panelGrid columns="3" >
                    <h:panelGrid columns="1">
                        <p:outputLabel style="margin: 5px; text-align: left" value="Nome da conta" />
                        <p:inputText  value="#{contaBean.conta.nome}" 
                                      required="true" requiredMessage="Informe o nome da conta" />
                    </h:panelGrid>

                    <h:panelGrid columns="1" style=" margin-left: 10px;">
                        <h:outputLabel style="margin: 5px;text-align: left;" for="da" value="Data de abertura" />
                        <p:calendar id="da" pattern="dd/MM/yyyy" yearRange="c-100:c+100" navigator="true" readonlyInput="true"
                                    maxdate="#{clienteBean.dataAtual}" value="#{contaBean.conta.dataAbertura}" 
                                    required="true" requiredMessage="Informe a data de abertura da conta."
                                    disabled="#{not empty contaBean.conta.id}"/>
                    </h:panelGrid>

                    <h:panelGrid columns="1" style=" margin-left: 10px;">
                        <h:outputLabel style="text-align: left;" value="Saldo" for="saldo" />                  
                        <p:inputText style="width: 200px; text-align: right" id="saldo" value="#{contaBean.conta.saldo}" styleClass="moeda" 
                                     disabled="#{not empty contaBean.conta.id}" required="true" requiredMessage="Informe o saldo da conta">
                            <f:convertNumber minFractionDigits="2" maxFractionDigits="2" locale="pt_BR" />
                        </p:inputText>
                    </h:panelGrid>
                </h:panelGrid>
                <h:panelGrid columns="3">
                    <h:panelGrid columns="1">
                        <h:outputLabel style="text-align: left;" value="Banco"  />                           
                        <p:selectOneMenu value="#{contaBean.conta.banco}" disabled="#{not empty contaBean.conta.id}"
                                         converter="entityConverter" style="padding-left: 2px; width: 200px;">
                            <f:selectItem itemLabel="Selecione um banco" itemValue="" noSelectionOption="true"/>
                            <f:selectItems value="#{bancoBean.bancos}" var="banco" itemLabel="#{banco.nomeBanco}"/>
                        </p:selectOneMenu>
                    </h:panelGrid>   

                    <h:panelGrid columns="1" style=" margin-left: 10px;">
                        <h:outputLabel style="text-align: left;" value="Número da Agência"  />
                        <p:inputText value="#{contaBean.conta.numeroAgencia}" 
                                     disabled="#{not empty contaBean.conta.id}" required="true" requiredMessage="Informe o número da conta.">
                        </p:inputText>
                    </h:panelGrid>
                    <h:panelGrid columns="1" style=" margin-left: 10px;">
                        <h:outputLabel style="text-align: left;" value="Nome da Agência"  />                        
                        <p:inputText value="#{contaBean.conta.agencia}" disabled="#{not empty contaBean.conta.id}"
                                     required="true" requiredMessage="Informe o nome da agência.">
                        </p:inputText>
                    </h:panelGrid>
                </h:panelGrid>

                <h:panelGrid columns="2" >
                    <h:panelGrid columns="1">
                        <h:outputLabel style="text-align: left;" value="Número da Conta"  />
                        <p:inputText value="#{contaBean.conta.agencia}" disabled="#{not empty contaBean.conta.id}"
                                     required="true" requiredMessage="Informe o número da conta.">
                        </p:inputText>
                    </h:panelGrid> 

                    <h:panelGrid columns="1" style=" margin-left: 10px;">
                        <h:outputLabel style="text-align: left;" value="Gerente"  />               
                        <p:inputText value="#{contaBean.conta.gerente}" style="width: 300px;"
                                     required="true" requiredMessage="Informe o nome do Gerente.">
                        </p:inputText>
                    </h:panelGrid>
                </h:panelGrid><br/>
                <p:commandButton value="Gravar"  action="#{contaBean.gravar}" rendered="#{empty contaBean.conta.id}" 
                                 style="margin-right: 10px;" icon="ui-icon-check" ajax="false" />
                <p:commandButton value="Alterar" action="#{contaBean.gravar}" rendered="#{not empty contaBean.conta.id}" style="margin-right: 10px;" icon="ui-icon-check" >
                    <p:confirm header="Confirmação" message="Deseja alterar a informação?" icon="ui-icon-alert" />
                    <p:confirmDialog global="true"  showEffect="fade" >
                        <p:commandButton value="Sim" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
                        <p:commandButton value="Não" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
                    </p:confirmDialog>
                </p:commandButton>
                <p:commandButton value="Encerrar Conta" action="#{contaBean.encerrarConta}"  rendered="#{not empty contaBean.conta.id}" 
                                 ajax="false" icon="ui-icon-close" style="margin-right: 10px;">
                    <p:confirm header="Confirmação" message="Confirma o encerramento da conta?" icon="ui-icon-alert" />
                    <p:confirmDialog global="false"  showEffect="fade" >
                        <p:commandButton value="Sim" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
                        <p:commandButton value="Não" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
                    </p:confirmDialog>
                </p:commandButton>
                <p:commandButton value="Voltar" action="#{contaBean.voltar()}" immediate="true" ajax="false" icon="ui-icon-arrowreturnthick-1-w"/>   
            </p:fieldset>
        </h:form>  
    </ui:define>

</ui:composition>
